using Aurora.TaskScheduler.Abstractions.Message;
using Aurora.TaskScheduler.Abstractions.Storage;
using Gateway.IQuery.TaskScheduler;
using Gateway.IQuery.TaskScheduler.Request;

namespace Gateway.Query;

/// <summary>
/// 
/// </summary>
public class TaskSchedulerQuery : ITaskSchedulerQuery
{
    private readonly IDataStorage _dataHandler;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="dataHandler"></param>
    public TaskSchedulerQuery(IDataStorage dataHandler)
    {
        _dataHandler = dataHandler;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="id"></param>
    /// <returns></returns>
    public async Task<AppTask> GetDetail(string id)
    {
        return await _dataHandler.GetDetail(id);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public async Task<List<AppTask>> GetList()
    {
        return await _dataHandler.GetAllJob();
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    public async Task<IQuery.PageResult<AppTaskLog>> GetLogPageList(TaskSchedulerLogPageRequest request)
    {
        var data = await _dataHandler.GetLogList(request.TaskId, request.Page, request.PageSize);
        return IQuery.PageResult<AppTaskLog>.Create(data.list, data.total);
    }

    /// <summary>
    /// 
    /// </summary>
    /// <returns></returns>
    public async Task<List<string>> GetClassJobDll()
    {
        return (await _dataHandler.GetListByTaskType(1)).Select(x => x.DllClassName).ToList();
    }
}